﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;

namespace Pai.LiveStation.ConsolePlayer
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0 && args[0] != null)
                Process.GetProcessById(Int32.Parse(args[0])).Kill();

            System.Console.Title = "Studio Radio Console Player version 1.0: For questions or concerns, contact Vivek Pai.";
            System.Console.WriteLine();
            System.Console.WriteLine("\n--------------------------------");
            System.Console.WriteLine("Studio Radio Console Player v.1.0");
            System.Console.WriteLine("--------------------------------");
            System.Console.WriteLine();

            System.Console.ForegroundColor = ConsoleColor.Red;
            RadioStation station = new RadioStation(
                ConfigurationManager.AppSettings["StationName"],
                ConfigurationManager.AppSettings["StationDescription"],
                ConfigurationManager.AppSettings["StationUrl"],
                ConfigurationManager.AppSettings["StationBroadcastService"]
                );

            System.Console.WriteLine("Initializing Studio Player...");
            ConsolePlayer player = new ConsolePlayer(station);

            System.Console.WriteLine("\n-Loading Station....");
            System.Console.ForegroundColor = ConsoleColor.DarkCyan;

            System.Console.WriteLine("\n--------------------------------");
            System.Console.WriteLine("\n Welcome to " + player.Hub.Name + "\n " + player.Hub.Description);
            System.Console.WriteLine("\n Station URL: " + player.Hub.WebAddress);
            System.Console.WriteLine("--------------------------------");

            System.Console.ForegroundColor = ConsoleColor.Red;

            try
            {
                System.Console.WriteLine();
                System.Console.ForegroundColor = ConsoleColor.Green;
                System.Console.WriteLine("\n-Starting Broadcast...");
                System.Console.ForegroundColor = ConsoleColor.White;

            }
            catch (Exception e)
            {
                System.Threading.Thread.Sleep(1000);
                Process.Start(Assembly.GetEntryAssembly().Location, Process.GetCurrentProcess().Id.ToString());
            }
            System.Console.ReadLine();
        }
    }
}
